home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / imagemap / imap_settings.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-05  |  6.1 KB  |  170 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "config.h"
  25.  
  26. #include "imap_browse.h"
  27. #include "imap_main.h"
  28. #include "imap_settings.h"
  29. #include "imap_string.h"
  30. #include "imap_table.h"
  31.  
  32. #include "libgimp/stdplugins-intl.h"
  33.  
  34. static MapFormat_t _map_format = CSIM;
  35.  
  36. static void
  37. settings_ok_cb(gpointer data)
  38. {
  39.    SettingsDialog_t *param = (SettingsDialog_t*) data;
  40.    MapInfo_t *info = get_map_info();
  41.  
  42.    g_strreplace(&info->image_name, gtk_entry_get_text(
  43.       GTK_ENTRY(param->imagename->file)));
  44.    g_strreplace(&info->title, gtk_entry_get_text(GTK_ENTRY(param->title)));
  45.    g_strreplace(&info->author, gtk_entry_get_text(GTK_ENTRY(param->author)));
  46.    g_strreplace(&info->default_url, 
  47.         gtk_entry_get_text(GTK_ENTRY(param->default_url)));
  48.    g_strreplace(&info->description, 
  49.         gtk_editable_get_chars(GTK_EDITABLE(param->description), 
  50.                        0, -1));
  51.    info->map_format = _map_format;
  52. }
  53.  
  54. static void
  55. type_toggled_cb(GtkWidget *widget, gpointer data)
  56. {
  57.    if (GTK_WIDGET_STATE(widget) & GTK_STATE_SELECTED)
  58.       _map_format = (MapFormat_t) data;
  59. }
  60.  
  61. static SettingsDialog_t*
  62. make_settings_dialog()
  63. {
  64.    SettingsDialog_t *data = g_new(SettingsDialog_t, 1);
  65.    GtkWidget *table, *vscrollbar, *frame, *hbox;
  66.    DefaultDialog_t *dialog;
  67.    GSList    *group;
  68.  
  69.    dialog = data->dialog = make_default_dialog(_("Settings for this Mapfile"));
  70.    default_dialog_set_ok_cb(dialog, settings_ok_cb, (gpointer) data);
  71.  
  72.    table = gtk_table_new(9, 3, FALSE);
  73.    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox), 
  74.              table);
  75.    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
  76.    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
  77.    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
  78.    gtk_widget_show(table);
  79.  
  80.    create_label_in_table(table, 0, 0, _("Filename:"));
  81.    data->filename = create_label_in_table(table, 0, 1, "");
  82.  
  83.    create_label_in_table(table, 1, 0, _("Image name:"));
  84.    data->imagename = browse_widget_new(_("Select Image File"));
  85.    gtk_table_attach_defaults(GTK_TABLE(table), data->imagename->hbox, 1, 2, 
  86.                  1, 2);
  87.  
  88.    create_label_in_table(table, 2, 0, _("Title:"));
  89.    data->title = create_entry_in_table(table, 2, 1);
  90.    create_label_in_table(table, 3, 0, _("Author:"));
  91.    data->author = create_entry_in_table(table, 3, 1);
  92.    create_label_in_table(table, 4, 0, _("Default URL:"));
  93.    data->default_url = create_entry_in_table(table, 4, 1);
  94.    create_label_in_table(table, 5, 0, _("Description:"));
  95.  
  96.    data->description = gtk_text_new(NULL, NULL);
  97.    gtk_text_set_editable(GTK_TEXT(data->description), TRUE);
  98.    gtk_table_attach(GTK_TABLE(table), data->description, 1, 2, 5, 8,
  99.             GTK_EXPAND | GTK_SHRINK | GTK_FILL,
  100.             GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  101.    gtk_widget_show(data->description);
  102.  
  103.    /* Add a vertical scrollbar to the GtkText widget */
  104.    vscrollbar = gtk_vscrollbar_new(GTK_TEXT(data->description)->vadj);
  105.    gtk_table_attach(GTK_TABLE(table), vscrollbar, 2, 3, 5, 8,
  106.             GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  107.    gtk_widget_show(vscrollbar);
  108.  
  109.    frame = gtk_frame_new(_("Map file format"));
  110.    gtk_widget_show(frame);
  111.    gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 2, 9, 10);
  112.    hbox = gtk_hbox_new(FALSE, 1);
  113.    gtk_container_add(GTK_CONTAINER(frame), hbox);
  114.    gtk_widget_show(hbox);
  115.  
  116.    data->ncsa = gtk_radio_button_new_with_label(NULL, "NCSA");
  117.    gtk_signal_connect(GTK_OBJECT(data->ncsa), "toggled", 
  118.               (GtkSignalFunc) type_toggled_cb, (gpointer) NCSA);
  119.    gtk_box_pack_start(GTK_BOX(hbox), data->ncsa, TRUE, TRUE, 10);
  120.    gtk_widget_show(data->ncsa);
  121.  
  122.    group = gtk_radio_button_group(GTK_RADIO_BUTTON(data->ncsa));
  123.    data->cern = gtk_radio_button_new_with_label(group, "CERN");
  124.    gtk_signal_connect(GTK_OBJECT(data->cern), "toggled", 
  125.               (GtkSignalFunc) type_toggled_cb, (gpointer) CERN);
  126.    gtk_box_pack_start(GTK_BOX(hbox), data->cern, TRUE, TRUE, 10);
  127.    gtk_widget_show(data->cern);
  128.  
  129.    group = gtk_radio_button_group(GTK_RADIO_BUTTON(data->cern));
  130.    data->csim = gtk_radio_button_new_with_label(group, "CSIM");
  131.    gtk_signal_connect(GTK_OBJECT(data->csim), "toggled", 
  132.               (GtkSignalFunc) type_toggled_cb, (gpointer) CSIM);
  133.    gtk_box_pack_start(GTK_BOX(hbox), data->csim, TRUE, TRUE, 10);
  134.    gtk_widget_show(data->csim);
  135.  
  136.    return data;
  137. }
  138.  
  139. void
  140. do_settings_dialog(void)
  141. {
  142.    static SettingsDialog_t *dialog;
  143.    const char *filename = get_filename();
  144.    MapInfo_t *info = get_map_info();
  145.  
  146.    if (!dialog)
  147.       dialog = make_settings_dialog();
  148.  
  149.    gtk_label_set_text(GTK_LABEL(dialog->filename), 
  150.               (filename) ? filename : _("<Untitled>"));
  151.    browse_widget_set_filename(dialog->imagename, info->image_name);
  152.    gtk_entry_set_text(GTK_ENTRY(dialog->title), info->title);
  153.    gtk_entry_set_text(GTK_ENTRY(dialog->author), info->author);
  154.    gtk_entry_set_text(GTK_ENTRY(dialog->default_url), info->default_url);
  155.  
  156.    if (info->map_format == NCSA)
  157.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->ncsa), TRUE);
  158.    else if (info->map_format == CERN)
  159.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->cern), TRUE);
  160.    else
  161.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->csim), TRUE);
  162.  
  163.    gtk_widget_grab_focus(dialog->imagename->file);
  164.    default_dialog_show(dialog->dialog);
  165.  
  166.    gtk_editable_delete_text(GTK_EDITABLE(dialog->description), 0, -1);
  167.    gtk_text_insert(GTK_TEXT(dialog->description), NULL, NULL, NULL,
  168.            info->description, -1);
  169. }
  170.